using System;
using System.Web.UI.WebControls;

public partial class MonthSelectControl : System.Web.UI.UserControl
{

    private DateTime _Value = DateTime.Now;

    public DateTime Value
    {
        get { return _Value; }
        set { _Value = value; }
    }

    protected void Page_Load(object sender, System.EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Value == DateTime.MinValue) Value = DateTime.Now;
            //txtYear.Text = DateTime.Now.Year.ToString();
            for (int i = 1960; i < 2100; i++)
            {
                ddlYear.Items.Add(i.ToString());
            }
            ddlYear.SelectedValue = DateTime.Today.Year.ToString();
        }
    }

    public void lnkMonthClick(object sender, EventArgs e)
    {
        int Month = 1;
        LinkButton btn = (LinkButton)sender;
        if (btn.Text == "Jan")
            Month = 1;
        if (btn.Text == "Feb")
            Month = 2;
        if (btn.Text == "Mar")
            Month = 3;
        if (btn.Text == "Apr")
            Month = 4;
        if (btn.Text == "May")
            Month = 5;
        if (btn.Text == "Jun")
            Month = 6;
        if (btn.Text == "Jul")
            Month = 7;
        if (btn.Text == "Aug")
            Month = 8;
        if (btn.Text == "Sep")
            Month = 9;
        if (btn.Text == "Oct")
            Month = 10;
        if (btn.Text == "Nov")
            Month = 11;
        if (btn.Text == "Dec")
            Month = 12;

        int Year;
        try
        {
            //Year = Int32.Parse(txtYear.Text);
            Year = Int32.Parse(ddlYear.SelectedValue);
        }
        catch { Year = DateTime.Now.Year; }
        this.Value = new DateTime(Year, Month, 1, 0, 0, 1);
        if (DateChanged != null)
            DateChanged.Invoke(this, new EventArgs());
    }

    public event EventHandler DateChanged;
}
